<?php
/**
 * 周舟 hzboye010@163.com
 * addby sublime snippets
 * Mmz Winner log Api
 */
namespace app\shop\api;
use app\common\api\BaseApi;
use app\shop\model\MmzWinnerPepole;

class MmzWinnerPepoleApi extends BaseApi{

	const ADD        = "shop/MmzWinnerPepoleApi/add";
	const COUNT      = "shop/MmzWinnerPepoleApi/count";
	const SAVE       = "shop/MmzWinnerPepoleApi/save";
	const SAVE_BY_ID = "shop/MmzWinnerPepoleApi/saveById";
	const GET_INFO   = "shop/MmzWinnerPepoleApi/getInfo";
	const SET_INC    = "shop/MmzWinnerPepoleApi/setInc";
	/*private*/
  const GET_INFO2 = "shop/MmzWinnerPepoleApi/getInfo2";
	const QUERY_WITH_PRO = "shop/MmzWinnerPepoleApi/queryWithPro";

  protected function _init(){
		$this->model = new MmzWinnerPepole();
	}

	public function queryWithPro($map = null, $page = ['curpage'=>1,'size'=>10], $order = false, $params = false, $fields = false) {
		$start = max(0,(intval($page['curpage'])-1)*intval($page['size']));
    $model = $this->model->alias('wp');
    $list = $model
    ->join('left join common_member cm on cm.uid=wp.uid') //head nickname
    ->where($map)->order($order)->field($fields)
    -> limit($start,$page['size']) -> select();

		// $list = $query -> page($page['curpage'] . ',' . $page['size']) -> select();
		if (false === $list) return $this -> apiReturnErr($this -> model -> getDbError());
		$count = $this -> model->alias('wp') -> where($map) -> count();
		return $this -> apiReturnSuc(["count" => $count, "list" => $list]);
  }
	/**
	 * 获取数据find
	 * @param $map
	 * @param bool $order
	 * @return array
	 */
	public function getInfo2($map,$order = false,$field = false) {
		$result = $this->model->alias('w')
		->join('left join itboye_mmz_apply_pepole as a on w.apply_id=a.id ')
		->where($map)->order($order)-> field($field) -> find();
		if (false === $result) {
		    return $this -> apiReturnErr($this -> model -> getDbError());
		} else {
		    if(empty($result)) $result = [];
		    return $this -> apiReturnSuc($result);
		}
	}
}